#include "video.h"
#include "defs.h"
#include "kc.h"


extern int videoCursor;
int actualAtribute=RED_TXT;
/*int actualAtribute=WHITE_TXT;*/

void 
putChar(int ascii)
{
	char * video = (char *) VIDEOMEMORY;

	video[videoCursor] = ascii;
	video[videoCursor+1]= actualAtribute;
	moveCursor(2);
	return;
}	

void
printAtRTCline(int ascii)
{
	
	char * video = (char *) VIDEOMEMORY;
	
	video[videoCursor] = ascii;
	video[videoCursor+1]= actualAtribute;
	videoCursor+=2; /*no controla que se haya ido de la pantalla*/
	return;
}


void
moveCursor(int cant)
{
	int aux=videoCursor;
	if( (videoCursor+=cant) >= SHOW_SCREEN_SIZE*2)
	{
		scrollDown();	
		videoCursor= (SHOW_SCREEN_SIZE*2)-(SCREEN_WIDE*2);
	}
	return;	
}

void
getCursorPosition(int *row, int *col)
{
	*col=videoCursor % (SCREEN_WIDE*2);
	*row=videoCursor / (SCREEN_WIDE*2);
	
	return;
}

void
setCursorPosition(int row, int col)
{
	if(row>SCREEN_LENGTH || col>SCREEN_WIDE*2)
		videoCursor=SCREEN_SIZE*2-1;
	else
		videoCursor=row*(SCREEN_WIDE*2) + col;
	return;
}


void
scrollDown(void)
{
	int row,col;
	char * video = (char *) VIDEOMEMORY;
	
	for(row=0; row<SHOW_SCREEN_LENGTH-1; row++)
		for(col=0; col<SCREEN_WIDE*2; col++ )
		{
			video[ row*(SCREEN_WIDE*2)+col ] = video[ (row+1)*(SCREEN_WIDE*2)+col ];
		}
		
	col=SHOW_SCREEN_SIZE*2-(SCREEN_WIDE*2);	
	
	for(; col < SHOW_SCREEN_SIZE*2; col+=2)
		video[col]=' ';
	return;
}





